﻿//    function for radiobutton
function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}
//    function for checkboxall
function CheckAll(obj) {
    var list = obj.parentNode.parentNode.parentNode;
    var chklist = list.getElementsByTagName("input");
    for (var i = 0; i < chklist.length; i++) {
        if (chklist[i].type == "checkbox" && chklist[i] != obj) {
            chklist[i].checked = obj.checked;
        }

    }
}

////
function setVal(val,id) {
    if (parseInt(val) == 0) {
        document.getElementById(id).innerHTML = "Student Name";
    }
    else if (parseInt(val) == 1) {
        document.getElementById(id).innerHTML = "Roll No.";
    }
    else if (parseInt(val) == 1) {
        document.getElementById(id).innerHTML = "Add No.";
    }
    else {
        document.getElementById(id).innerHTML = "Card Id ";
    }

}
function printbarcode(bid,sid,staffid,barcodeid) {
    var list = document.getElementById("tbbarcode");
    var chklist = list.getElementsByTagName("input");
    var count = 0;
    var img = "";
    var cnt_card = 0;
        for (var i = 1; i < chklist.length; i++) {
            if (chklist[i].type == "checkbox") {
                if (chklist[i].checked) {
                    if (document.getElementById(bid).checked) {
                        if (document.getElementById(barcodeid).checked) {
                            img += "<div class='barcode'>"
                            img += chklist[i].parentNode.parentNode.cells[3].innerHTML
                            img += "</div>"
                            img += "<div class='alt_barcode'>"
                            img += chklist[i].parentNode.parentNode.cells[3].innerHTML
                            img += "</div>"
                        }
                        else {
                            img += ""
                        }
                    }
                    else if (document.getElementById(sid).checked) {
                        if (document.getElementById(barcodeid).checked) {
                            img += "<div class='barcode'>"
                            img += chklist[i].parentNode.parentNode.cells[15].innerHTML
                            img += "</div>"
                            img += "<div class='alt_barcode'>"
                            img += chklist[i].parentNode.parentNode.cells[15].innerHTML
                            img += "</div>"
                        }
                        else {
                            img += Student_Icard(chklist, i, cnt_card);
                            cnt_card += 1;
                        }
                    }
                    else {
                        if (document.getElementById(barcodeid).checked) {
                            img += "<div class='barcode'>"
                            img += chklist[i].parentNode.parentNode.cells[11].innerHTML
                            img += "</div>"
                            img += "<div class='alt_barcode'>"
                            img += chklist[i].parentNode.parentNode.cells[11].innerHTML
                            img += "</div>"
                        }
                        else {
                            img += Staff_ICard(chklist, i, cnt_card)
                            cnt_card += 1;
                        }
                    }
                    count += 1;
                }
            }
        }
    if (parseInt(count) > 0) {
        var class_name = "";
        var wn = window.open('Barcode of Accession', '', 'width=400,height=800,scrollbars=1');
        var str = "";
        var background = "";
        var color = "";
        if (document.getElementById('sChoose_Color')) {
            background = document.getElementById('sChoose_Color').value;
            color = document.getElementById('sChhoseTextColor').value;
        }
        var style_back = "";
        var style_back_color = "";
        if (background != '') {
            style_back = ".stuImage_Border{border:4px solid " + background + "!important;}";
            style_back_color = ".bk_color{background-color:" + background + "!important;}";
        }
        var txt_color = "";
        if (color != '') {
             txt_color = ".txt_color{color:" + color + " !important}";
        }

        if (!(document.getElementById(barcodeid).checked)) {
            class_name = "M_ICard.css";
            if (document.getElementById(staffid).checked) {
                class_name = "Icard.css";
            }
        }
        str += "<html><head><title>Print Preview::Barcode of Accession</title><link href='" + class_name + "' rel='stylesheet' type='text/css'/><style type='text/css'>@media print,screen{.barcode{width:50%;float:left;} .alt_barcode{margin-left:4%;width:46%;float:left;} " + style_back + style_back_color +txt_color+" .break{page-break-after:always} body{margin:0px}}</style></head><body>"
        str += img;
        str += "</body></html>"
        wn.document.body.innerHTML = "";  
        wn.document.write(str);
        wn.print();
        //wn.close();
    }
    else {
        alert("Please select at least one barcode for print.")
    }
}
function Student_Icard(chklist, i,cnt) {
    var count = 0;
    var bar_img = "";
    var stu_img = "";
    var str = ""

    var first_head = "Solitaire Infosys Pvt. Ltd.";
    var second_head = "Industerial Area Phase-8";
    var third_head = "Mohali";
    var forth_head = "\"We Provide Best IT Solution\"";
    var footer = "Email:info.slinfy.com&nbsp;&nbsp;,http://www.slinfy.com </br><center>Tel:-01764-233517,232248</center>"
    var principal_text = "Director"


//    var first_head = "Mata Gujri College";
//    var second_head = "Fatehgarh Sahib";
//    var third_head = "An Autonomous College";
//    var forth_head = "\"College with Potential For Excellence\"";
//        var footer = "Email:info.matagujricollege.org&nbsp;&nbsp;,http://www.matagujricollege.org </br><center>Tel:-01763-233715,232247</center>"
//    var principal_text="Director-Principal"

    ////Anandpur sahib college****************************
//        var first_head = "Sri Guru Teg Bahadur</br> Khalsa College";
//        var second_head = "Sri Anandpur Sahib(Distt.Ropar)";
//        var third_head = "";
//        var forth_head = "";
//        var footer = "Ph.:01887232037, &nbsp;&nbsp;,info@sgtbcollege.org.in&nbsp;&nbsp;http://www.sgtbcollege.org.in/,"
//        var principal_text = 'Principal';

            var studentname = chklist[i].parentNode.parentNode.cells[4].innerHTML;
            var course = chklist[i].parentNode.parentNode.cells[5].innerHTML;
            var rollno = chklist[i].parentNode.parentNode.cells[3].innerHTML;
            var fathername = chklist[i].parentNode.parentNode.cells[8].innerHTML;
            var mothername = chklist[i].parentNode.parentNode.cells[9].innerHTML;
            var mobno = chklist[i].parentNode.parentNode.cells[11].innerHTML;
            var dob = chklist[i].parentNode.parentNode.cells[10].innerHTML;
            var address = chklist[i].parentNode.parentNode.cells[13].getElementsByTagName('div')[0].innerHTML;
            var bloodgroup = chklist[i].parentNode.parentNode.cells[12].innerHTML;
            var cardid = chklist[i].parentNode.parentNode.cells[14].innerHTML;
            var img_tag = chklist[i].parentNode.parentNode.cells[15].getElementsByTagName('img')[0];
            var address1 = address.substring(0, 38);
            var address2 = address.substring(39, address.length);
            
            if (img_tag) {
                bar_img = img_tag.src;
            }
            var studdent_img_tag = chklist[i].parentNode.parentNode.cells[2].getElementsByTagName('img')[0];
            if (studdent_img_tag) {
                stu_img = studdent_img_tag.src;
            }
            //if (parseInt(cnt) % 2 == 0) {
                if ((parseInt(cnt)) % 5 == 0 && cnt!==0) {
                    str += '<div class="page_break">';
                }
                else {
                    str += '<div class="no_page_break">';
                }
            //}
            str += '<div class="page">';
            str += '<div class="container" style="float:left;">';
//            str += '<div id="header_line" class="Header_line" >';
//            str += '</div>'
            str += '<div id="header" >'
            str += '<div id="Header_logo_name" class="float">'
            str += '<div id="header_text " class="logo_card bk_color">'
            str += '<div class="log_img">'
            str += '<img src="Images/logo.jpg" alt="logo" height="40" width="40"  />'
            str += '</div>'
            str += '<div class="first_head txt_color">'
            str += first_head
            str += '</div>'
            str += '<div class="second_head txt_color">'
            str += second_head
            str += '</div>'
            str += '<div class="second_head txt_color" >';
            str += third_head
            str += '</div>'
//            str += '<div class="third_head">'
//            str += 'Accredited \'A\' Grade By NAAC,Banglore'
//            str += '</div>'
            str += '<div class="third_head txt_color">'
            str += forth_head 
            str += '</div>'
            str += '</div>'
            str += '<div class="marg_ph">'
            str += '<div id="name" class="left_lbl">Name :</div>'
            str += '<div class="right_lbl">' + studentname + '</div>'
            str += '<div class="clear"></div>'
            str += '<div id="class" class="left_lbl">Class :</div>';
            str += '<div class="right_lbl right_lbl_pho">' + course + '</div>';
            str += '<div id="rollno" class="left_lbl">Roll No. :</div>'
            str += '<div class="right_lbl right_lbl_pho">' + rollno + '</div>'
            str += '<div class="clear" ></div>'
            str += '<div id="fathername" class="left_lbl">Father`s Name :</div>'
            str += '<div class="right_lbl">' + fathername + '</div>'
            str += '<div class="clear"></div>'
            str += '<div id="mothername" class="left_lbl">Mother`s Name :</div>'
            str += '<div class="right_lbl">' + mothername + '</div>'
            str += '</div>'
            str += '</div>'
            str += '<div class="stu_img stuImage_Border">'
            str+='<div>Id : '+cardid+'</div>'
            str += '<img src="' + stu_img + '" alt="Student_image"  />'
            str += '</div>'
            str += '</div>'
            str += '<div class="clear" ></div>'
//            str += '<div id="information" class="information">'
            //str += '<div class="clear"></div>'
//            str += '<div class="clear"></div>'
//            str += '<div id="mothername" class="left_lbl">Mother`s Name :</div>'
//            str += '<div class="right_lbl">' + mothername + '</div>'
//            str += '<div id="dob" class="left_lbl">D.O.B :</div>'
//            str += '<div class="right_lbl right_lbl_pho">' + dob + '</div>'
//            str += '<div class="clear"></div>'
//            str += '<div id="Contact" class="left_lbl">Mob No.:</div>'
//            str += '<div class="right_lbl">' + mobno + '</div>'
//            str += '<div id="bl_grp" class="left_lbl">Blood Group:</div>'
//            str += '<div class="right_lbl right_lbl_pho">' + bloodgroup + '</div>'
//            str += '<div class="clear"></div>'
//            str += '<div id="address" class="left_lbl">Address :</div>'
//            str += '<div class="address">'
//            str += address1
//            str += '</div>'
//            str += '<div class="address">'
//            str += address2
//            str += '</div>'
//            str += '</div>'
            str += '<div id="barcode_image">'
            str += '<div class="barcode_img">'
            str += '<img src="' + bar_img + '" alt="Barcode Image">'
            str += '</div>'
            str += '<div class="pr_txt">'
            str += '<div>'
            str += '<img id="sig" alt="Principal Signature" src="Images/sig.jpg" height="26px" width="100px" />'
            str += '</div>'
            str += '<div>'
            str += principal_text 
            str += '</div>'
            str += '</div>'
            str += '</div>'
            str += '<div class="clear"></div>'
//            str += '<div id="footer" class="Header_line" >'
//            str += footer
//            str += '</div>'
            str += '</div>'
            str += '</div>'
            str += '<div class="page">';
            str += '<div class="container" style="float:left;">';
            str += '<div class="b_info"><div id="Contact" class="left_lbl marg_ph">Mob No.:</div>'
            str += '<div class="right_lbl marg_ph">' + mobno + '</div>'
                        str += '<div id="bl_grp" class="left_lbl marg_ph">Blood Group:</div>'
                        str += '<div class="right_lbl right_lbl_pho marg_ph">' + bloodgroup + '</div>'
                        str += '<div class="clear"></div>'
                        str += '<div id="dob" class="left_lbl">D.O.B :</div>'
                        str += '<div class="right_lbl right_lbl_pho">' + dob + '</div>'
                        str += '<div class="clear"></div>'
                                    str += '<div id="address" class="left_lbl">Address :</div>'
                                    str += '<div class="address">'
                                    str += address1
                                    str += '</div>'
                                  //  str+='<div class="clear"></div>'
                                    str += '<div class="address address2">'
                                    str += address2
                                    str += '</div>'
                                    str += "</div>"
//                                    str+='<div class="clear"></div>'
//                                    str += '<div id="Header_logo_name">'
//                                    str += '<div id="header_text" class="logo_card footer_header">'
//                                    str += '<div class="first_head">'
//                                    str += first_head
//                                    str += '</div>'
//                                    str += '<div class="second_head">'
//                                    str += second_head
//                                    str += '</div>'
//                                    str += '<div class="second_head" >';
//                                    str += third_head
//                                    str += '</div>'
////                                    //            str += '<div class="third_head">'
////                                    //            str += 'Accredited \'A\' Grade By NAAC,Banglore'
////                                    //            str += '</div>'
//                                    str += '<div class="third_head thirdhead_footer">'
//                                    str += forth_head
//                                    str += '</div>'
//                                    str += '</div>'
//                                    str += '</div>'
                                    str += '<div id="footer" class="Header_line bk_color txt_color">'
                                    str += footer
                                    str += '</div>'
        
            str += "</div>"
//            if (parseInt(cnt) % 2 != 0) {
               str += '</div>';
           // }
    return str;
}
function Staff_ICard(chklist, i, cnt) {

//mata gujri college****************************
//    var first_head = "Mata Gujri College";
//    var second_head = "Fatehgarh Sahib";
//    var third_head = "An Autonomous College";
//    var forth_head = "\"College with Potential For Excellence\"";
//    var footer = "Email:-info.matagujricollege.org,www.matagujricollege.org&nbsp;&nbsp;Tel:-01763-233715,232247"

    ////Anandpur sahib college****************************
    var first_head = "Sri Guru Teg Bahadur Khalsa College";
    var second_head = "'Sri Anandpur Sahib(Distt.Ropar)'";
    var third_head = "info@sgtbcollege.org.in";
    var forth_head = "Ph.:01887232037 &nbsp;&nbsp;http://www.sgtbcollege.org.in/";
    var footer = ""

    var str = ""
    var personname = chklist[i].parentNode.parentNode.cells[3].innerHTML;
    var fathername = chklist[i].parentNode.parentNode.cells[4].innerHTML;
    var designation = chklist[i].parentNode.parentNode.cells[5].innerHTML;
    var department = chklist[i].parentNode.parentNode.cells[6].innerHTML;
    var dob = chklist[i].parentNode.parentNode.cells[7].innerHTML;
    var phoneno = chklist[i].parentNode.parentNode.cells[8].innerHTML;
    var address = chklist[i].parentNode.parentNode.cells[9].innerHTML;
    var img_tag = chklist[i].parentNode.parentNode.cells[11].getElementsByTagName('img')[0];
    var staff_img_tag = chklist[i].parentNode.parentNode.cells[2].getElementsByTagName('img')[0];
    var barcode = chklist[i].parentNode.parentNode.cells[10].innerHTML;
    var validupto = chklist[i].parentNode.parentNode.cells[12].getElementsByTagName('input')[0];
    var staff_image = "";
    var barcode_image = "";
    if (img_tag) {
        barcode_image = img_tag.getAttribute('src');
    }
    if (staff_img_tag) {
        staff_image = staff_img_tag.getAttribute('src');
    }
    if (parseInt(cnt) % 2 == 0) {
        if ((parseInt(cnt)) % 8 == 0 && cnt !== 0) {
            str += '<div class="page_break">';
        }
        else {
            str += '<div class="no_page_break">';
        }
    }
    str+='<div class="page"><div class="container">'
    str += '<div class="logo_card">'
    str+='<img src="Images/logo.jpg" alt="logo" height="40" width="40"  />'
    str += '</div><div class="header_all">'
    str += '<div id="Div4" class="first_head">'
    str+=first_head
    str+='</div>' 
    str += '<div id="Div6" class="second_head"  >'
    str+=second_head
    str+='</div>'
    str += '<div id="Div7" class="third_head">'
    str+=third_head
    str+='</div>'
    str += '<div id="Div8" class="third_head">'
    str+=forth_head
    str += '</div></div>'
    str += '<div class="name_prsn img_h_w">'
    str += '<div class="barcode">' + barcode + '</div>'
    str += '<img src="' + staff_image + '" alt="image" />'
    str += "</div>"
    str += '<div class="information txt_card">'
    str += '<div class="name_prsn">' + personname + '</div>'
    str += '<div class="left_lbl">S.o/D.o/W.o :</div>'
    str+='<div class="right_lbl">'+fathername+'</div>'
    str+="<div class='clear'></div>"
    str += '<div class="left_lbl">Designation :</div>'
    str+='<div class="right_lbl">'+designation+'</div>'
   
    str += "<div class='clear'></div>"
    str += '<div class="left_lbl">Department :</div>'
    str += '<div class="right_lbl">' + department + '</div>'
    str += "<div class='clear'></div>"
    str+='<div class="left_lbl">D.O.B :</div>'
    str+='<div class="right_lbl">'+dob+'</div>'
    str += "<div class='clear'></div>"
    str+='<div class="left_lbl">Mob No. :</div>'
    str += '<div class="right_lbl">' + phoneno + '</div>'
    str += "<div class='clear'></div>"
    str += '<div class="left_lbl">Valid Upto :</div>'
    str += '<div class="right_lbl">' + validupto.value + '</div>'
    str += '</div>'
    str += '<div class="left_lbl txt_card">Address :</div>'
    str += '<div class="address1 txt_card">' + address + '</div>'
    str+='<div class="txt_card ">'
    str+='<div class="sig_h_w" style="text-align:center">'
                    str+='<img src="Images/sig.jpg" alt="sig_image" class="sig_h_w"  />'
                        str+='<div class="txt_card" style="text-align:center;">';
                      str+='Principal';
                      str += '</div>';
                 str+='</div>'
            str+='</div>'
       str += '<div style="text-align:center"><img id="Img2" src="' + barcode_image + '" style="min-height:20px; min-width:100px" alt="barcode_image" /></div>'
       str += '</div></div>';
    if (parseInt(cnt) % 2 != 0) {
        str += '</div>';
    }
    return str;
}

function filldate(ele) {
    var ele_name = document.getElementsByName("validupto");
    for (var i = 0; i < ele_name.length; i++) {
        ele_name[i].value = ele.value;
    } 
}